home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWShLiSh.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  10.5 KB  |  320 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWShLiSh.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWSHLISH_H
  13. #include "FWShLiSh.h"
  14. #endif
  15.  
  16. // ----- Foundation Includes -----
  17.  
  18. #ifndef FWSTREAM_H
  19. #include "FWStream.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. // File scope definitions
  24. //========================================================================================
  25.  
  26. #ifdef FW_BUILD_MAC
  27. #pragma segment FWGraphics_ShapeListShape
  28. #endif
  29.  
  30. //========================================================================================
  31. //    class FW_CShapeListShape
  32. //========================================================================================
  33.  
  34. FW_DEFINE_AUTO(FW_CShapeListShape)
  35. FW_DEFINE_CLASS_M1(FW_CShapeListShape, FW_CShape)
  36.  
  37. // This class is archivable, but we provide the archiving implementation in a separate
  38. // translation unit in order to enable deadstripping of the archiving-related code
  39. // in parts that do not use archiving with this class.
  40.  
  41. //----------------------------------------------------------------------------------------
  42. // FW_CShapeListShape::FW_CShapeListShape
  43. //----------------------------------------------------------------------------------------
  44.  
  45. FW_CShapeListShape::FW_CShapeListShape(const FW_PShapeList& list) :
  46.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  47.     fShapeList(list)
  48. {
  49.     FW_END_CONSTRUCTOR
  50. }
  51.  
  52. //----------------------------------------------------------------------------------------
  53. // FW_CShapeListShape::FW_CShapeListShape
  54. //----------------------------------------------------------------------------------------
  55.  
  56. FW_CShapeListShape::FW_CShapeListShape(FW_CReadableStream& stream) :
  57.     FW_CShape(stream),
  58.     fShapeList(stream)
  59. {
  60.     FW_END_CONSTRUCTOR
  61. }
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // FW_CShapeListShape::FW_CShapeListShape
  65. //----------------------------------------------------------------------------------------
  66.  
  67. FW_CShapeListShape::FW_CShapeListShape(const FW_CShapeListShape& other) :
  68.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  69.     fShapeList(other.fShapeList)
  70. {
  71.     FW_END_CONSTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. // FW_CShapeListShape::~FW_CShapeListShape
  76. //----------------------------------------------------------------------------------------
  77.  
  78. FW_CShapeListShape::~FW_CShapeListShape()
  79. {
  80.     FW_START_DESTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // FW_CShapeListShape::HitTestList
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CShape* FW_CShapeListShape::HitTestList(FW_CGraphicContext& gc,
  88.                                            const FW_CPoint& test,
  89.                                            FW_Fixed tolerance) const
  90. {
  91.     // Shapes are rendered in reverse order of the list so I need to test them from
  92.     // first (frontmost) to last (backmost)
  93.     FW_CShapeListIterator ite(fShapeList);
  94.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  95.     {
  96.         if(shape->HitTest(gc, test, tolerance))
  97.             return shape;
  98.     }    
  99.     return NULL;
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. // FW_CShapeListShape::operator=
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_CShapeListShape& FW_CShapeListShape::operator=(const FW_CShapeListShape& other)
  107. {
  108.     fShapeList = other.fShapeList;
  109.     return *this;
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // FW_CShapeListShape::GetShapeList
  114. //----------------------------------------------------------------------------------------
  115.  
  116. const FW_PShapeList& FW_CShapeListShape::GetShapeList() const
  117. {
  118.     return fShapeList;
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // FW_CShapeListShape::GetShapeList
  123. //----------------------------------------------------------------------------------------
  124.  
  125. FW_PShapeList& FW_CShapeListShape::GetShapeList()
  126. {
  127.     return fShapeList;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // FW_CShapeListShape::GetUnSharedShapeList
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_PShapeList& FW_CShapeListShape::GetUnSharedShapeList()
  135. {
  136.     if (fShapeList->GetReferenceCount() > 1)
  137.         fShapeList = fShapeList.Copy();
  138.  
  139.     return fShapeList;
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // FW_CShapeListShape::SetShapeList
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CShapeListShape::SetShapeList(const FW_PShapeList& list)
  147. {
  148.     fShapeList = list;
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. // FW_CShapeListShape::Purge
  153. //----------------------------------------------------------------------------------------
  154.  
  155. void FW_CShapeListShape::Purge()
  156. {
  157.     fShapeList->Purge();
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // FW_CShapeListShape::Render
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_CShapeListShape::Render(FW_CGraphicContext& gc) const
  165. {
  166.     // Draw shapes in reverse order of the list
  167.     FW_CShapeListIterator ite(fShapeList);
  168.     for (FW_CShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
  169.     {
  170.         shape->Render(gc);
  171.     }    
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. // FW_CShapeListShape::Render
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void FW_CShapeListShape::RenderShapeList(FW_CGraphicContext& gc,
  179.                                          const FW_PShapeList& shapeList)
  180. {
  181.     // Draw shapes in reverse order of the list
  182.     FW_CShapeListIterator ite(shapeList);
  183.     for (FW_CShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
  184.     {
  185.         shape->Render(gc);
  186.     }    
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. // FW_CShapeListShape::Copy
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CShape* FW_CShapeListShape::Copy() const
  194. {
  195.     return FW_NEW(FW_CShapeListShape, (*this));
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. // FW_CShapeListShape::HitTest
  200. //----------------------------------------------------------------------------------------
  201.  
  202. FW_Boolean FW_CShapeListShape::HitTest(FW_CGraphicContext& gc,
  203.                                         const FW_CPoint& test,
  204.                                         FW_Fixed tolerance) const
  205. {
  206.     if (GetRenderVerb() == FW_kNoRendering)
  207.         return NULL;
  208.  
  209.     return HitTestList(gc, test, tolerance) != NULL;
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // FW_CShapeListShape::Transform
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void FW_CShapeListShape::Transform(Environment *ev, ODTransform* transform)
  217. {
  218.     FW_CShapeListIterator ite(fShapeList);
  219.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  220.     {
  221.         shape->Transform(ev, transform);
  222.     }    
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // FW_CShapeListShape::InverseTransform
  227. //----------------------------------------------------------------------------------------
  228.  
  229. void FW_CShapeListShape::InverseTransform(Environment *ev, ODTransform* transform)
  230. {
  231.     FW_CShapeListIterator ite(fShapeList);
  232.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  233.     {
  234.         shape->InverseTransform(ev, transform);
  235.     }    
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. // FW_CShapeListShape::MoveShape
  240. //----------------------------------------------------------------------------------------
  241.  
  242. void FW_CShapeListShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  243. {
  244.     FW_CShapeListIterator ite(fShapeList);
  245.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  246.     {
  247.         shape->MoveShape(deltaX, deltaY);
  248.     }    
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. // FW_CShapeListShape::MoveShapeTo
  253. //----------------------------------------------------------------------------------------
  254.  
  255. void FW_CShapeListShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
  256. {
  257.     FW_CPoint shapeListAnchor(GetAnchorPoint());
  258.     FW_CPoint delta(x - shapeListAnchor.x, y - shapeListAnchor.y);
  259.     
  260.     FW_CShapeListIterator ite(fShapeList);
  261.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  262.     {
  263.         shape->MoveShape(delta.x, delta.y);
  264.     }    
  265. }
  266.     
  267. //----------------------------------------------------------------------------------------
  268. // FW_CShapeListShape::Inset
  269. //----------------------------------------------------------------------------------------
  270.  
  271. void FW_CShapeListShape::Inset(FW_Fixed h, FW_Fixed v)
  272. {
  273.     FW_CShapeListIterator ite(fShapeList);
  274.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  275.     {
  276.         shape->Inset(h, v);
  277.     }    
  278. }
  279.     
  280. //----------------------------------------------------------------------------------------
  281. // FW_CShapeListShape::GetBounds
  282. //----------------------------------------------------------------------------------------
  283.  
  284. void FW_CShapeListShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  285. {
  286.     FW_Boolean first = TRUE;
  287.  
  288.     FW_CShapeListIterator ite(fShapeList);
  289.     for (FW_CShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  290.     {
  291.         FW_CRect bounds;
  292.         shape->GetBounds(gc, bounds);
  293.         if (first)
  294.             rect = bounds;
  295.         else
  296.             rect.Union(bounds);
  297.         first = FALSE;
  298.     }    
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. //    FW_CShapeListShape::GetAnchorPoint
  303. //----------------------------------------------------------------------------------------
  304.  
  305. FW_CPoint FW_CShapeListShape::GetAnchorPoint() const
  306. {
  307.     return fShapeList->GetAnchorPoint();
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. // FW_CShapeListShape::Flatten
  312. //----------------------------------------------------------------------------------------
  313.  
  314. void FW_CShapeListShape::Flatten(FW_CWritableStream& stream) const
  315. {
  316.     FW_CShape::Flatten(stream);
  317.     stream << fShapeList;
  318. }
  319.  
  320.